/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/**
 * @Title: Main.java
 * @Package phoenics.apeak.simple.service
 * @Description
 * @author phoenics@126com
 * @date 2016-1-30 16:01:32
 * @version V1.0
 */
package phoenics.apeak.simple.service;


import phoenics.apeak.crawl.Crawl;
import phoenics.apeak.simple.config.SimpleConfig;

// TODO: Auto-generated Javadoc
/**
 * The Class Main.
 *
 * @Description The Class Main.
 */
public class Main {

	/**
 * The main method.
 *
 * @param args
 *            the arguments
 * @throws InterruptedException
 *             the interrupted exception
 * @Description The main method.
 */
	public static void main(String[] args) throws InterruptedException {
		String ini="";
		if(args.length<4){
			System.out.println("args is at least 3!");
			return;
		}
		if(args.length<5){
			ini=args[3].toLowerCase().trim();
		}
		
		SimpleConfig.host=args[0];
		SimpleConfig.port=Integer.parseInt(args[1]);
		SimpleConfig.collection=args[2];
		Crawl crawl=new Crawl();
		if(ini.equals("new")){
			initCrawl(crawl);
			return;
		}
		if(ini.equals("newrun")){
			initCrawl(crawl);
			Thread.sleep(1000*30);
			runCrawl(crawl);
			return;
		}
		runCrawl(crawl);
	}
	
	/**
 * Run crawl.
 *
 * @param crawl
 *            the crawl
 * @Description Run crawl.
 */
	private static void runCrawl(Crawl crawl){
		System.out.println("run crawl . . .");
		crawl.runCrawl(SimpleConfig.class, FireUrl.class);
	}
	
	/**
 * Inits the crawl.
 *
 * @param crawl
 *            the crawl
 * @Description Inits the crawl.
 */
	private static void initCrawl(Crawl crawl){
		System.out.println("Initialize crawl . . .");
		crawl.runCrawl4Ini(SimpleConfig.class, FireUrl.class);
	}
	
	/**
 * Write agents.
 *
 * @Description Write agents.
 */
	
}
